<?php ob_start();

class Admin extends Controller {

	function Admin()
	{
		parent::Controller();
		$this->load->library('Validation');
		$this->load->library('Pagination');
		}

	function index()
	{

 		$data = "";
		$rules['username'] = "required";
		$rules['password'] = "required";
		$this->validation->set_rules($rules);

		$fields['username'] = "Username";
		$fields['password'] = "Password";
		$this->validation->set_fields($fields);

		$user = $this->Admin_model->login_validation($this->validation->username, $this->validation->password);
        $this->session->set_userdata('user', $user);


		$this->login();
		}
	function login(){

	    $data = "";
		$rules['username'] = "required";
		$rules['password'] = "required";
		$this->validation->set_rules($rules);

		$fields['username'] = "Username";
		$fields['password'] = "Password";
		$this->validation->set_fields($fields);


		 $user = $this->Admin_model->login_validation($this->validation->username, $this->validation->password);

		$this->session->set_userdata('user',$user);
		$this->session->userdata('user');

		if ($this->validation->run() == FALSE)
		{
		$this->load->view('admin/login', $data);

		}
		else{

	         if ($user =='1')
			{
				$data['user'] = $this->Admin_model->getDetails($user);
				$data['message']="";

				redirect('/admin/home', 'refresh');

			}



            else
            {
            	// Incorrect Username/Password
				$data['user'] = "";
				$data['message'] = "Incorrect username/password !";
				$this->load->view('admin/login', $data);
            }

		}

	}

	function forgot()
	{

		$data = "";
		$data['user'] = "";
	    $user_id = $this->session->userdata('userSessId');
		$data['user'] = $this->Users_m->getDetails($user_id);
		$data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
        $data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

		$this->session->set_userdata(array ('prev_page' => 'home'));

		$this->load->library('email');

		$rules['email'] = "required|valid_email";
		$this->validation->set_rules($rules);

		$fields['email'] = 'email';
		$this->validation->set_fields($fields);

		$buffer = strlen('/admin/forgot/');
		$data['redirect_to'] = substr($this->uri->uri_string(), $buffer);

		if ($this->validation->run() == FALSE)
		{

	        $this->load->view('admin/forgot/forgot_temp.php', $data);


		}
		else
		{
			$result = $this->Admin_model->checkEmailId($this->validation->email);

			if ($result == 0)
			{
				$this->session->set_userdata(array ('prev_page' => 'login'));
				$data['forgot'] = "Your are not registered with this site.!";

				$this->load->view('admin/forgot/forgot_temp.php', $data);


			}
			else
			{
				$this->session->set_userdata(array ('prev_page' => 'login'));
				$generate_password = $this->Admin_model->createRandomPassword();
				$password =$generate_password;
				$this->Admin_model->resetPwd($this->validation->email, $password);

				$this->email->from('admin@processtalent.com', 'admin@processtalent.com');
				$this->email->to($this->validation->email);

				$this->email->subject('Password Reset');
				$this->email->message("As per your request your password has been reset. \n\nYour New Password : $password  \n\nAfter login, you can use 'Change password' option to change this password.");

				$this->email->send();

				$data['forgot'] = "Your new password has been sent to your Email";

				$this->load->view('admin/forgot/forgot_temp.php', $data);



			}
		  }
	}





	function Home()
	{

     	$user=$this->session->userdata('user');
     	$data['user'] = $this->Users_m->getDetails($user);
        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);


        $data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

		$this->load->view('layout/header' , $data);
		$this->load->view('layout/footer' , $data);
	}
	function Hierarchy()
	{

		$user=$this->session->userdata('user');
     	$data['user'] = $this->Users_m->getDetails($user);
        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

		$this->load->view('layout/header' , $data);
		$this->load->view('layout/footer' , $data);


	}

	function Buyers()
	{
        $user=$this->session->userdata('user');
     	$data['user'] = $this->Users_m->getDetails($user);
        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

		$this->load->view('layout/header' , $data);
		$this->load->view('layout/footer' , $data);
	}

 	function Sellers()
	{
        $user=$this->session->userdata('user');
     	$data['user'] = $this->Users_m->getDetails($user);
        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

		$this->load->view('layout/header' , $data);
		$this->load->view('layout/footer' , $data);
	}

	function Products()
	{
     	$user=$this->session->userdata('user');
     	$data['user'] = $this->Users_m->getDetails($user);
        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

		$this->load->view('layout/header' , $data);
		$this->load->view('layout/footer' , $data);
	}

	function Commission()
	{
        $user=$this->session->userdata('user');
     	$data['user'] = $this->Users_m->getDetails($user);
		$data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

		$this->load->view('layout/header' , $data);
		$this->load->view('layout/footer' , $data);
	}

	function Setting()
	{
     	$user=$this->session->userdata('user');
     	$data['user'] = $this->Users_m->getDetails($user);
        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

		$this->load->view('layout/header' , $data);
		$this->load->view('layout/footer' , $data);
	}

	function Enquiry()
	{
     	$user=$this->session->userdata('user');
     	$data['user'] = $this->Users_m->getDetails($user);
        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

		$this->load->view('layout/header' , $data);
		$this->load->view('layout/footer' , $data);
	}

	function Reports()
	{
     	$user=$this->session->userdata('user');
     	$data['user'] = $this->Users_m->getDetails($user);
        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

		$this->load->view('layout/header' , $data);
		$this->load->view('layout/footer' , $data);
	}

	function CMS()
	{
     	$user=$this->session->userdata('user');
     	$data['user'] = $this->Users_m->getDetails($user);
        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

		$this->load->view('layout/header' , $data);
		$this->load->view('layout/footer' , $data);
	}
    function Logout()
	{


        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

		$this->load->view('layout/header' , $data);
		$this->load->view('layout/footer' , $data);
		$user_id = $this->session->userdata('userSessId');
		if($user_id != "")
		{
			$this->session->sess_destroy();

		}
			/*redirect()$this->login();*/
			redirect('/admin/login', 'refresh');


	}

	function category_list()
	{
    $user=$this->session->userdata('user');
    $data['user'] = $this->Users_m->getDetails($user);


        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

        $config['base_url'] = base_url().'/index.php/admin/category_list/';
		$total_rows= $this->Admin_model->toal_catlist();
      	$config['total_rows']= $total_rows;
 		//get the number of records
		$config['per_page'] = '5';//display perpage
		$config['num_links'] = 3;
		$config['cur_page'] = $this->uri->segment(3);
		$config['full_tag_open'] = '<p>';
		$config['full_tag_close'] = '</p>';
		$this->pagination->initialize($config);

        $data['category_list'] = $this ->Admin_model->category_list($config['per_page'],$this->uri->segment(3));


    $this->load->view('layout/header' , $data);
    $this->load->view('categories/category_list');
    $this->load->view('layout/footer' , $data);
    }

    function add_category()
    {
    $user=$this->session->userdata('user');
    $data['user'] = $this->Users_m->getDetails($user);


        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);
        $this->session->set_userdata(array ('prev_page' => 'category_list'));

        $rules['category'] = "required";
		$this->validation->set_rules($rules);

		$fields['category'] = "Category";
		$this->validation->set_fields($fields);
        if($this->validation->run() == FALSE )
        {
		$this->load->view('layout/header' , $data);
	    $this->load->view('categories/category_add');
	    $this->load->view('layout/footer' , $data);
        }
        else
        {
            $category = $_POST['category'];
            $checkcat_list = $this->Admin_model->check_cat($category);
			if($checkcat_list !="")
			{
				$data['duplicate'] = 'This category already exists! You can not insert Again.';
				$this->session->set_userdata(array('duplicate' => 'This category already exists! You can not insert Again.'));
			}



			else
			{
			if(isset($_POST['category']))
			{
				$category = $_POST['category'];
                $categoryid = $this->Admin_model->add_newscategories($category);

                 redirect('/admin/category_list', 'refresh');
			}
			}






        $this->load->view('layout/header' , $data);
	    $this->load->view('categories/category_add');
	    $this->load->view('layout/footer' , $data);


    }
    }


function categoryedit()
{
    $user=$this->session->userdata('user');
    $data['user'] = $this->Users_m->getDetails($user);

        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);
        $this->session->set_userdata(array ('prev_page' => 'category_list'));

        $uriid = $this->uri->segment(3);
		$data['category'] = $this->Admin_model->editcategory($uriid);


		if(isset($_POST['category']))
		{

		$this->Admin_model->update_newscategories($_POST['category'],$_POST['categoryid']);
        redirect('/admin/category_list', 'refresh');

       }

       else
       {
       	$this->load->view('layout/header' , $data);
	    $this->load->view('categories/category_add');
	    $this->load->view('layout/footer' , $data);
       }

}

   function categorydelete($id)
	{
	 $this->Admin_model->category_delete($id);

	 redirect('/admin/category_list', 'refresh');
	}

	function subcategory_list()
	{
    $user=$this->session->userdata('user');
    $data['user'] = $this->Users_m->getDetails($user);

        $this->session->set_userdata(array ('prev_page' => 'subcategory_list'));
        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

        $config['base_url'] = base_url().'/index.php/admin/subcategory_list/';
		$total_rows= $this->Admin_model->toal_subcatlist();
      	$config['total_rows']= $total_rows;
 		//get the number of records
		$config['per_page'] = '5';//display perpage
		$config['num_links'] = 3;
		$config['cur_page'] = $this->uri->segment(3);
		$config['full_tag_open'] = '<p>';
		$config['full_tag_close'] = '</p>';
		$this->pagination->initialize($config);

        $data['subcategory_list'] = $this ->Admin_model->subcategory_list($config['per_page'],$this->uri->segment(3));


    $this->load->view('layout/header' , $data);
    $this->load->view('categories/subcategory_list');
    $this->load->view('layout/footer' , $data);
	}

	function addsub_category()
	{
	$user=$this->session->userdata('user');
    $data['user'] = $this->Users_m->getDetails($user);
    $data['category_listitems'] = $this->Admin_model->category_listitems();


        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);
        $this->session->set_userdata(array ('prev_page' => 'subcategory_list'));
        $rules['category'] = "required";
        $rules['sub_category'] = "required";
		$this->validation->set_rules($rules);

		$fields['category'] = "Maincategory";
		$fields['sub_category'] = "Subcategory";
		$this->validation->set_fields($fields);



        if($this->validation->run() == FALSE )
        {
		$this->load->view('layout/header' , $data);
	    $this->load->view('categories/add_subcategory');
	    $this->load->view('layout/footer' , $data);
        }


        else
        {
           $category = $_POST['category'];
		   $sub_category = $_POST['sub_category'];

            $checksub_list = $this->Admin_model->check_subcat($category ,$sub_category);
			if($checksub_list !="")
			{
				$data['duplicate'] = 'This subcategory already exists under the category! You can not insert Again.';
				$this->session->set_userdata(array('duplicate' => 'This subcategory already exists under this category! You can not insert Again.'));
			}

			else
			{

			if(isset($_POST['sub_category']))
			{
                $categoryid = $this->Admin_model->add_subcategories($category,$sub_category);

			 redirect('/admin/subcategory_list', 'refresh');
			}
			}

        $this->load->view('layout/header' , $data);
	    $this->load->view('categories/add_subcategory');
	    $this->load->view('layout/footer' , $data);


    }
	}


function sub_categoryedit()
{
    $user=$this->session->userdata('user');
    $data['user'] = $this->Users_m->getDetails($user);

        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);
        $this->session->set_userdata(array ('prev_page' => 'subcategory_list'));

        $uriid = $this->uri->segment(3);
		$data['category'] = $this->Admin_model->edit_subcategory($uriid);


		if(isset($_POST['category']))
		{

		$this->Admin_model->update_subcategories($_POST['category'],$_POST['categoryid']);
        redirect('/admin/subcategory_list', 'refresh');
        }

       else
       {
       	$this->load->view('layout/header' , $data);
	    $this->load->view('categories/add_subcategory');
	    $this->load->view('layout/footer' , $data);
       }
}

function sub_categorydelete($id)
{
	$this->Admin_model->sub_category_delete($id);
    redirect('/admin/subcategory_list', 'refresh');
}


 function process_list()
 {
    $user=$this->session->userdata('user');
    $data['user'] = $this->Users_m->getDetails($user);
    $this->session->set_userdata(array ('prev_page' => 'add_process'));

        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

        $config['base_url'] = base_url().'/index.php/admin/process_list/';
		$total_rows= $this->Admin_model->process_totallist();

     	$config['total_rows']= $total_rows;
 		//get the number of records
		$config['per_page'] = '5';//display perpage
		$config['num_links'] = 3;
		$config['cur_page'] = $this->uri->segment(3);
		$config['full_tag_open'] = '<p>';
		$config['full_tag_close'] = '</p>';
		$this->pagination->initialize($config);

        $data['process_list'] = $this ->Admin_model->process_listitems($config['per_page'],$this->uri->segment(3));
        // var_dump( $data['process_list']);

    $this->load->view('layout/header' , $data);
    $this->load->view('categories/process_list');
    $this->load->view('layout/footer' , $data);
	}


 function add_process()
 {

    $user=$this->session->userdata('user');
    $data['user'] = $this->Users_m->getDetails($user);
    $data['category_listitems'] = $this->Admin_model->category_listitems();
    $data['subcategory_listitems'] = $this->Admin_model->subcategory_listitems();


        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);
        $this->session->set_userdata(array ('prev_page' => 'add_process'));

        $rules['subcategory'] = "required";
        $rules['process'] = "required";

		$this->validation->set_rules($rules);


		$fields['subcategory'] = "Subcategory";
		$fields['process'] = "Process";

		$this->validation->set_fields($fields);



        if($this->validation->run() == FALSE )
        {
		$this->load->view('layout/header' , $data);
	    $this->load->view('categories/add_process');
	    $this->load->view('layout/footer' , $data);
        }

        else
        {

		   $sub_category = $_POST['subcategory'];
		   $process = $_POST['process'];

            $checksub_list = $this->Admin_model->check_subcat($sub_category , $process);
			if($checksub_list !="")
			{
				$data['duplicate'] = 'This process already exists  under the subcategory! You can not insert Again.';
				$this->session->set_userdata(array('duplicate' => 'This process already exists under the subcategory! You can not insert Again.'));
			}

			else
			{

			if(isset($_POST['process']))
			{
                $categoryid = $this->Admin_model->add_process($sub_category , $process);

			 redirect('/admin/process_list', 'refresh');
			}
			}

        $this->load->view('layout/header' , $data);
	    $this->load->view('categories/add_process');
	    $this->load->view('layout/footer' , $data);


    }
 }

    function process_edit()
    {

    $user=$this->session->userdata('user');
    $data['user'] = $this->Users_m->getDetails($user);

        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);
        $this->session->set_userdata(array ('prev_page' => 'process_list'));

        $uriid = $this->uri->segment(3);
		$data['process_edit'] = $this->Admin_model->edit_process($uriid);


		if(isset($_POST['process']))
		{

		$this->Admin_model->update_process($_POST['process'],$_POST['categoryid']);
        redirect('/admin/process_list', 'refresh');
        }

       else
       {
       	$this->load->view('layout/header' , $data);
	    $this->load->view('categories/add_process');
	    $this->load->view('layout/footer' , $data);
       }
    }


   function process_delete($id)
   {
   	$this->Admin_model->process_delete($id);
    redirect('/admin/process_list', 'refresh');
   }


    function doctype_list()
    {
    $user=$this->session->userdata('user');
    $data['user'] = $this->Users_m->getDetails($user);
    $this->session->set_userdata(array ('prev_page' => 'add_process'));

        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

        $config['base_url'] = base_url().'/index.php/admin/doctype_list/';
		$total_rows= $this->Admin_model->doctype_totallist();

     	$config['total_rows']= $total_rows;
 		//get the number of records
		$config['per_page'] = '5';//display perpage
		$config['num_links'] = 3;
		$config['cur_page'] = $this->uri->segment(3);
		$config['full_tag_open'] = '<p>';
		$config['full_tag_close'] = '</p>';
		$this->pagination->initialize($config);

        $data['doctype_list'] = $this ->Admin_model->doctype_listitems($config['per_page'],$this->uri->segment(3));
        // var_dump( $data['process_list']);

    $this->load->view('layout/header' , $data);
    $this->load->view('categories/doctype_list');
    $this->load->view('layout/footer' , $data);
    }
    function doctype_add()
    {
    $user=$this->session->userdata('user');
    $data['user'] = $this->Users_m->getDetails($user);
    $data['category_listitems'] = $this->Admin_model->category_listitems();
    $data['subcategory_listitems'] = $this->Admin_model->subcategory_listitems();
    $data['processlist'] = $this->Admin_model->processlist();

        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);
        $this->session->set_userdata(array ('prev_page' => 'doctype_add'));

        $rules['process'] = "required";
        $rules['doctype'] = "required";

		$this->validation->set_rules($rules);


		$fields['process'] = "Process";
		$fields['doctype'] = "Doctype";

		$this->validation->set_fields($fields);

        if($this->validation->run() == FALSE )
        {
		$this->load->view('layout/header' , $data);
	    $this->load->view('categories/doctype_add');
	    $this->load->view('layout/footer' , $data);
        }

        else
        {

		   $process = $_POST['process'];
		   $doctype = $_POST['doctype'];

            $checksub_list = $this->Admin_model->check_doctype($process,$doctype);
			if($checksub_list !="")
			{
				$data['duplicate'] = 'This doctype already exists under the process! You can not insert Again.';
				$this->session->set_userdata(array('duplicate' => 'This doctype already exists under the process! You can not insert Again.'));
			}

			else
			{

			if(isset($_POST['doctype']))
			{
            $categoryid = $this->Admin_model->add_doctype($process , $doctype);

			 redirect('/admin/doctype_list', 'refresh');
			}
			}

        $this->load->view('layout/header' , $data);
	    $this->load->view('categories/doctype_add');
	    $this->load->view('layout/footer' , $data);


    }


    }

    function doctype_edit()
    {
		$user=$this->session->userdata('user');
    	$data['user'] = $this->Users_m->getDetails($user);

        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);
        $this->session->set_userdata(array ('prev_page' => 'process_list'));

        $uriid = $this->uri->segment(3);
		$data['doctype_edit'] = $this->Admin_model->doctype_edit($uriid);


		if(isset($_POST['doctype']))
		{

		$this->Admin_model->doctype_update($_POST['doctype'],$_POST['categoryid']);
        redirect('/admin/doctype_list', 'refresh');
        }

       else
       {
       	$this->load->view('layout/header' , $data);
	    $this->load->view('categories/doctype_add');
	    $this->load->view('layout/footer' , $data);
       }
    }
    function doctype_delete($id)
    {
    $this->Admin_model->doctypedelete($id);
    redirect('/admin/doctype_list', 'refresh');
    }

    function cms_list()
    {
		$user=$this->session->userdata('user');
    	$data['user'] = $this->Users_m->getDetails($user);

        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

		$data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);

        $config['base_url'] = base_url().'/index.php/admin/cms_list/';
		$config['total_rows']= $this->db->count_all('cms_content');

 		//get the number of records
		$config['per_page'] = '5';//display perpage
		$config['num_links'] = 3;
		$config['cur_page'] = $this->uri->segment(3);
		$config['full_tag_open'] = '<p>';
		$config['full_tag_close'] = '</p>';
		$this->pagination->initialize($config);

        $data['cms_list'] = $this ->Admin_model->cms_list($config['per_page'],$this->uri->segment(3));
        // var_dump($data['cms_list']);

        $this->load->view('layout/header' , $data);
	    $this->load->view('cms/cms_list');
	    $this->load->view('layout/footer' , $data);

    }

    function cms_add()
    {
     $user=$this->session->userdata('user');
     $data['user'] = $this->Users_m->getDetails($user);



        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);
        $this->session->set_userdata(array ('prev_page' => 'cms_list'));

        $rules['cms_name'] = "required";
        $rules['cms_type'] = "required";
        $rules['cms_description'] = "required";

		$this->validation->set_rules($rules);


		$fields['cms_name'] = "CMS Name";
		$fields['cms_type'] = "CMS Type";
		$fields['cms_description'] = "Description";


		$this->validation->set_fields($fields);

        if($this->validation->run() == FALSE )
        {
		$this->load->view('layout/header' , $data);
	    $this->load->view('cms/cms_add');
	    $this->load->view('layout/footer' , $data);
        }

        else
        {

		   $cmsname = $_POST['cms_name'];
		   $cmstype = $_POST['cms_type'];
		   $cmsdescription = $_POST['cms_description'];

            $checksub_list = $this->Admin_model->check_cms($cmsname,$cmstype);
			if($checksub_list !="")
			{
				$data['duplicate'] = 'This cms name already exists! You can not insert Again.';
				$this->session->set_userdata(array('duplicate' => 'This cms name already exists! You can not insert Again.'));
			}

			else
			{

			if(isset($_POST['cms_name']))
			{
            $categoryid = $this->Admin_model->add_cms($cmsname ,$cmstype,$cmsdescription);

			 redirect('/admin/cms_list', 'refresh');
			}
			}

        $this->load->view('layout/header' , $data);
	    $this->load->view('cms/cms_add');
	    $this->load->view('layout/footer' , $data);


    }

    }

    function cms_edit()
    {
    $user=$this->session->userdata('user');
    $data['user'] = $this->Users_m->getDetails($user);

        $data['page_url'] =$this->uri->segment(2);
        $page_url =$this->uri->segment(2);
		$data['linkarray'] = $this ->Admin_model->sidelinks($page_url);
        $this->session->set_userdata(array ('prev_page' => 'cms_list'));

        $uriid = $this->uri->segment(3);
		$data['cms_edit'] = $this->Admin_model->cms_edit($uriid);
		if(isset($_POST['cms_name']))
		{

		$this->Admin_model->update_cms($_POST['cmsid'],$_POST['cms_name'],$_POST['cms_type'],$_POST['cms_description']);
        redirect('/admin/cms_list', 'refresh');
        }

       else
       {
       	$this->load->view('layout/header' , $data);
	    $this->load->view('cms/cms_add' ,$data);
	    $this->load->view('layout/footer' , $data);
       }
    }


   function cms_delete($id)
   {
	$this->Admin_model->cms_delete($id);
    redirect('/admin/cms_list', 'refresh');
   }


}
